/*
 * @Author: your name
 * @Date: 2022-04-12 19:14:42
 * @LastEditTime: 2022-04-12 22:10:11
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /safe_transmission_platform/src/codec.h
 */
#ifndef __DANIEL_CODEC_H__
#define __DANIEL_CODEC_H__

#include <iostream>
#include <string>
#include "requestMsg.pb.h"
#include "respondMsg.pb.h"
#include <memory>
namespace daniel
{
    class Codec
    {
    public:
        using ptr=std::shared_ptr<Codec>;
        Codec();
        virtual ~Codec();
        virtual std::string encodeMsg() = 0;
        virtual void *decodeMsg() = 0;
    };
    struct RequestInfo
    {
        int32_t cmd;
        std::string clientID;
        std::string serverID;
        std::string sign; 
        std::string data;
    };
    struct RespondInfo
    {
        int32_t status; 
        int seckeyID;
        std::string clientID; 
        std::string serverID;
        std::string data;
    };
    class RequestCodec : public Codec
    {
    public:
        using ptr=std::shared_ptr<RequestCodec>;
        RequestCodec();
        RequestCodec(const std::string& encodeStr);
        RequestCodec(const RequestInfo& reqInfo);
        void initMsg(const std::string &encodeStr);
        void initMsg(const RequestInfo& reqInfo);
        virtual std::string encodeMsg() override;
        virtual void *decodeMsg() override;
        ~RequestCodec() override;

    private:
        std::string m_encodeStr;
        RequestMsg m_msg;
    };

    class ResponseCodec : public Codec
    {
    public:
        using ptr=std::shared_ptr<ResponseCodec>;
        ResponseCodec();
        ResponseCodec(const std::string& encodeStr);
        ResponseCodec(const RespondInfo& respondInfo);
        void initMsg(const std::string &encodeStr);
        void initMsg(const RespondInfo& respondInfo);
        virtual std::string encodeMsg() override;
        virtual void *decodeMsg() override;
        ~ResponseCodec() override;

    private:
        std::string m_encodeStr;
        RespondMsg m_msg;
    };
}

#endif
